// RequireJS configuration
/*global requirejs */
requirejs.config({
    waitSeconds: 3,
    packages: [],
    paths: {
        jquery: '../vendor/jquery/jquery',
        MathJax: '//cdn.bootcss.com/mathjax/2.5.3/MathJax.js?config=TeX-AMS_HTML',
        pagedown: '../vendor/pagedown/js/Markdown.Converter',
        pagedownExtra: '../vendor/pagedown/js/Markdown.Extra',
        prettify: '../vendor/prettify/prettify'
    },
    shim: {
        pagedown: {
            exports: "Markdown"
        },
        pagedownExtra: {
            exports: "Markdown.Extra",
            deps: ["pagedown"]
        },
        MathJax: {
            exports: "MathJax"
        }
    }
});

// RequireJS entry point. By requiring synchronizer, publisher, sharing and
// media-importer, we are actually loading all the modules
require([
    "jquery",
    "pagedown",
    "MathJax",
    "pagedownExtra",
    "prettify"
], function($, Markdown, MathJax) {
    $(function() {
        // 现在来解析Markdown
        var text = $('#article-content').text();
        var mdc = new Markdown.Converter();
        Markdown.Extra.init(mdc, {
            extensions: "all",
            highlighter: "prettify"
        });

        var html = mdc.makeHtml(text);
        $('#article-content').empty().html(html);
        // 格式化代码
        prettyPrint();
        // 解析数学公式
        MathJax.Hub.Config({
            showProcessingMessages: false,
            delayStartupUntil: "configured",
            tex2jax: { inlineMath: [['$','$'],['\\(','\\)']] }
        });
        setTimeout(function () {MathJax.Hub.Configured();}, 2000);
    });
});